"""
Update the distribution of Android events from community to organization
"""
import ssl
from pymisp import PyMISP, ExpandedPyMISP
from mispconn.utils import CFG

ssl._create_default_https_context = ssl._create_unverified_context


def init(url, key):
    return ExpandedPyMISP(url, key, ssl=False)

misp = init(url=CFG['misp']['url'], key=CFG['misp']['key'])

# Query events
events = misp.search(controller='events',
                     metadata=True,
                     tags='file-type:type="android"',
                     with_attachments=False,
                     pythonify=True)

for event in events:
    # event = misp.get_event(r['id'], pythonify=True)
    if event.distribution == 1:
        event.distribution = 0
    misp.update_event(event)
    print(event.id)

print('Done')
